<template>
  <div class="stage-list">
    <div
      v-for="(item, index) in dataList"
      :key="index"
      class="stage-item"
    >
      <div class="stage-header">
        <div class="circle-container">
          <div
            class="outer-circle"
            :class="{ active: item.expanded }"
          >
            <div
              class="inner-circle"
              :class="{ active: item.expanded }"
            ></div>
          </div>
        </div>
        <div class="stage-name">{{ item.nodeStage }}</div>
        <!-- <el-switch
          v-model="item.expanded"
          active-color="#409EFF"
          inactive-color="#dcdfe6"
          @change="onSwitchChange(index)"
        ></el-switch> -->
      </div>

      <!-- <div v-if="item.expanded" class="stage-detail"> -->
      <div class="stage-detail">
        <div
          class="stage-detail-time"
          v-if="item.nodeStage !== '竣工验收'"
        >
          <span>计划开始时间</span>
          <el-date-picker
            v-model="item.planStartTime"
            type="date"
            placeholder="选择日期"
            size="small"
            :disabled="isDetail"
            @change="onStartTimeChange(item)"
          />
        </div>
        <div
          class="stage-detail-time"
          v-if="item.nodeStage !== '竣工验收'"
        >
          <span>预计完成时间</span>
          <el-date-picker
            v-model="item.planEndTime"
            type="date"
            placeholder="选择日期"
            size="small"
            :disabled="isDetail"
            @change="onEndTimeChange(item)"
          />
        </div>
        <div class="stage-detail-time">
          <span>实际完成时间</span>
          <el-date-picker
            v-model="item.actuallyTime"
            type="date"
            placeholder="选择日期"
            size="small"
            :disabled="isDetail"
            @change="onActuallyTimeChange(item)"
          />
        </div>
        <!-- <div class="stage-detail-time">
          <span>是否关键节点</span>
          <el-radio-group v-model="item.keyFlag">
            <el-radio label="是"></el-radio>
            <el-radio label="否"></el-radio>
          </el-radio-group>
        </div> -->
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'StageList',
  props: {
    stageList: {
      type: Array,
      required: true
    },
    isDetail: {
      type: Boolean
    }
  },
  data() {
    return {
      dataList: []
    }
  },
  watch: {
    stageList(val) {
      this.dataList = val.map((item) => {
        return {
          ...item,
          expanded: item.keyFlag === '是' ? true : false
        }
      })
    }
  },
  methods: {
    onSwitchChange(index) {
      // this.$emit('input', this.stages)
    },

    getStageList() {
      return this.dataList
    },

    // onStartTimeChange(item) {
    //   this.validateTimes(item)
    // },

    // onEndTimeChange(item) {
    //   this.validateTimes(item)
    // },

    // onActuallyTimeChange(item) {
    //   this.validateTimes(item)
    // },

    validateTimes(item) {
      const start = new Date(item.planStartTime)
      const end = new Date(item.planEndTime)
      const actual = new Date(item.actuallyTime)

      if (item.planEndTime && start && end < start) {
        this.$message.warning(
          '计划完成时间不能早于计划开始时间'
        )
        item.planEndTime = null
      }

      if (item.actuallyTime && start && actual < start) {
        this.$message.warning(
          '实际完成时间不能早于计划开始时间'
        )
        item.actuallyTime = null
      }
    }
  }
}
</script>

<style scoped>
.stage-list {
  /* border: 1px solid #e4e7ed; */
  border-radius: 6px;
  padding: 10px;
}
.stage-item {
  border-top: 1px solid #ebeef5;
  padding: 10px 0;
}
.stage-header {
  display: flex;
  align-items: center;
  cursor: pointer;
}
.circle-container {
  margin-right: 10px;
}
.outer-circle {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 1px solid #dcdfe6;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.3s;
  background-color: rgba(0, 186, 255, 0.2);
}
.outer-circle.active {
  /* border-color: rgba(0, 186, 255, 0.8); */
  background-color: rgba(0, 186, 255, 0.2);
}

.inner-circle {
  width: 10px;
  height: 10px;
  /* background-color: #dcdfe6;  */
  border-radius: 50%;
  transition: background-color 0.3s;
  background-color: rgba(0, 186, 255, 0.8);
}

.inner-circle.active {
  background-color: rgba(0, 186, 255, 0.8); /* 蓝色内部 */
}

.stage-name {
  flex: 1;
  color: #303133;
}

.stage-detail-time {
  span {
    font-size: 14px;
    color: #606061;
    margin-right: 10px;
  }

  margin: 10px 0;
}
.rotated {
  transform: rotate(180deg);
  transition: transform 0.2s;
}
</style>
